package com.javaweb.servlet.action;
import com.javaweb.servlet.bean.User;
import com.javaweb.servlet.utils.DBUtil;
import jdk.nashorn.internal.ir.CallNode;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

    @WebServlet("/user/exit")
    public class ExitServlet extends HttpServlet {
        @Override
        protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            String servletPath=request.getServletPath();
            if (servletPath.equals("/user/exit")) {
                doExit(request,response);
            }
        }
        protected void doExit(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            HttpSession session=request.getSession();
            if (session!=null) {
                //从session域中删除user对象
                session.removeAttribute("user");
                //手动销毁session对象
                session.invalidate();
                }
                //跳转到登录页面
                response.sendRedirect(request.getContextPath()+"/index.jsp");
        }
    }

